package au.edu.jcu.it.numberguess;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ListAdapter extends ArrayAdapter<HighScore> {
	private List<HighScore> highScores;

	public ListAdapter(Context context, int resource, List<HighScore> objects) {
		super(context, resource, objects);
		this.highScores = objects;

	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {

			LayoutInflater vi;
			vi = LayoutInflater.from(getContext());
			v = vi.inflate(R.layout.listitem, null);
		}

		HighScore hs = highScores.get(position);

		if (hs != null) {

			TextView tvNumber = (TextView) v.findViewById(R.id.number);
			TextView tvName = (TextView) v.findViewById(R.id.name);
			TextView tvScore = (TextView) v.findViewById(R.id.score);
			TextView tvDateTime = (TextView) v.findViewById(R.id.datetime);

			if (tvNumber != null) {
				tvNumber.setText(hs.getID());
			}
			if (tvName != null) {

				tvName.setText(hs.getName());
			}
			if (tvScore != null) {

				tvScore.setText(hs.getScore());
			}
			if (tvDateTime != null) {

				tvDateTime.setText(hs.getDate());
			}
		}

		return v;
	}
}
